-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add "Create API Token" and "Delete API Token" calls #148
base: main
Are you sure you want to change the base?
Conversation
feat(axiom-py): Add support for creating and deleting API tokens
Update `axiom-py` fork to v0.5.0
Update to v0.8.0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you so much for your contribution! Left a few notes, very happy to pair on the tokens client if you want
# Ability to ingest data. Optional. | ||
ingest: Optional[list[Literal["create"]]] = field(default=None) | ||
# Ability to query data. Optional. | ||
query: Optional[list[Literal["read"]]] = field(default=None) | ||
# Ability to use starred queries. Optional. | ||
starredQueries: Optional[ | ||
list[Literal["create", "read", "update", "delete"]] | ||
] = field(default=None) | ||
# Ability to use virtual fields. Optional. | ||
virtualFields: Optional[ | ||
list[Literal["create", "read", "update", "delete"]] | ||
] = field(default=None) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is missing data, trim and vacuum:
# Ability to ingest data. Optional. | |
ingest: Optional[list[Literal["create"]]] = field(default=None) | |
# Ability to query data. Optional. | |
query: Optional[list[Literal["read"]]] = field(default=None) | |
# Ability to use starred queries. Optional. | |
starredQueries: Optional[ | |
list[Literal["create", "read", "update", "delete"]] | |
] = field(default=None) | |
# Ability to use virtual fields. Optional. | |
virtualFields: Optional[ | |
list[Literal["create", "read", "update", "delete"]] | |
] = field(default=None) | |
# Data management capability. Optional. | |
data: Optional[list[Literal["delete"]]] = field(default=None) | |
# Ability to ingest data. Optional. | |
ingest: Optional[list[Literal["create"]]] = field(default=None) | |
# Ability to query data. Optional. | |
query: Optional[list[Literal["read"]]] = field(default=None) | |
# Ability to use starred queries. Optional. | |
starredQueries: Optional[ | |
list[Literal["create", "read", "update", "delete"]] | |
] = field(default=None) | |
# Trim capability. Optional | |
trim: Optional[list[Literal["update"]]] = field(default=None) | |
# Vacuum capability. Optional | |
vacuum: Optional[list[Literal["update"]]] = field(default=None) | |
# Ability to use virtual fields. Optional. | |
virtualFields: Optional[ | |
list[Literal["create", "read", "update", "delete"]] | |
] = field(default=None) |
apiTokens: Optional[ | ||
list[Literal["create", "read", "update", "delete"]] | ||
] = field(default=None) | ||
# Ability to access billing. Optional. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing audit log:
# Ability to access billing. Optional. | |
# Audit log capability. Optional. | |
auditLog: Optional[ | |
list[Literal["read"]] | |
] = field(default=None) | |
# Ability to access billing. Optional. |
def create_api_token(self, opts: TokenAttributes) -> Token: | ||
"""Creates a new API token with permissions specified in a TokenAttributes object.""" | ||
res = self.session.post( | ||
"/v2/tokens", | ||
data=ujson.dumps(asdict(opts), default=handle_json_serialization), | ||
) | ||
|
||
# Return the new token and ID. | ||
response = res.json() | ||
return Token(id=response["id"], token=response["token"]) | ||
|
||
def delete_api_token(self, token_id: str) -> None: | ||
"""Delete an API token using its ID string.""" | ||
self.session.delete(f"/v2/tokens/{token_id}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please move this into a TokenClient
in tokens.py
, similar to
axiom-py/src/axiom_py/datasets.py
Lines 49 to 55 in c9ec206
class DatasetsClient: # pylint: disable=R0903 | |
"""DatasetsClient has methods to manipulate datasets.""" | |
session: Session | |
def __init__(self, session: Session): | |
self.session = session |
Hello,
A few weeks ago, we discussed submitting a pull request with the "create / delete API token" logic that we have been using to programmatically set up API keys using the
axiom-py
package. Sorry for the delay in submitting this - I was OOTO recently and just got around to it.The logic should be fairly simple, and I did my best to structure the API parameters according to your documentation and existing conventions. But please let me know if you have any questions or concerns.
Thank you!